//
//  ComplaintsDetaileModel.swift
//  Pods
//
//  Created by eme on 2017/4/11.
//
//

import UIKit
import SwiftyJSON
import NetWorkCore
import ModelProtocol

class ComplaintsDetaileModel: ModelProtocol {
    
    // MARK: Declaration for string constants to be used to decode and also serialize.
    internal let kComplaintsDetaileComplaindateKey: String = "complaindate"
    internal let kComplaintsDetaileReplydateKey: String = "replydate"
    internal let kComplaintsDetaileComplainsourceKey: String = "complainsource"
    internal let kComplaintsDetaileReplyKey: String = "reply"
    internal let kComplaintsDetaileDetailidKey: String = "detailid"
    internal let kComplaintsDetaileDealeridKey: String = "dealerid"
    internal let kComplaintsDetaileAppraiseridKey: String = "appraiserid"
    internal let kComplaintsDetaileDetailKey: String = "detail"
    internal let kComplaintsDetailePicurlKey: String = "picurl"
    internal let kComplaintsDetaileComplainidKey: String = "complainid"
    internal let kComplaintsDetaileComplainTypeIdKey: String = "complainTypeId"
    internal let kComplaintsDetaileDealerKey: String = "dealer"
    internal let kComplaintsDetaileOsOrderComplainTypeKey: String = "osOrderComplainType"
    internal let kComplaintsDetaileIsdealKey: String = "isdeal"
    internal let kComplaintsDetaileComplaincommnetKey: String = "complaincommnet"
    
    
    // MARK: 属性
    var complaindate: String
    var replydate: String
    var complainsource: String
    var reply: String
    var detailid: String
    var dealerid: Int
    var appraiserid: Int
    var detail: DetailModel
    var picurl: String
    var complainid: Int
    var complainTypeId: Int
    var dealer: String
    var osOrderComplainType: OsOrderComplainTypeModel
    var isdeal: String
    var complaincommnet: String
    var picurlArr:[String]{
        get{
            let pic = picurl as NSString
            let picArr = pic.components(separatedBy: ",")
            return picArr
        }
    }
    
    
    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    required  init?(json: JSON) {
        complaindate = json[kComplaintsDetaileComplaindateKey].stringValue
        replydate = json[kComplaintsDetaileReplydateKey].stringValue
        complainsource = json[kComplaintsDetaileComplainsourceKey].stringValue
        reply = json[kComplaintsDetaileReplyKey].stringValue
        detailid = json[kComplaintsDetaileDetailidKey].stringValue
        dealerid = json[kComplaintsDetaileDealeridKey].intValue
        appraiserid = json[kComplaintsDetaileAppraiseridKey].intValue
        detail = DetailModel(json: json[kComplaintsDetaileDetailKey])!
        picurl = json[kComplaintsDetailePicurlKey].stringValue
        complainid = json[kComplaintsDetaileComplainidKey].intValue
        complainTypeId = json[kComplaintsDetaileComplainTypeIdKey].intValue
        dealer = json[kComplaintsDetaileDealerKey].stringValue
        osOrderComplainType = OsOrderComplainTypeModel(json: json[kComplaintsDetaileOsOrderComplainTypeKey])!
        isdeal = json[kComplaintsDetaileIsdealKey].stringValue
        complaincommnet = json[kComplaintsDetaileComplaincommnetKey].stringValue
        
    }
    
    
    /**
     Generates description of the object in the form of a NSDictionary.
     - returns: A Key value pair containing all valid values in the object.
     */
    internal func dictionaryRepresentation() -> [String : AnyObject ] {
        
        var dictionary: [String : AnyObject ] = [ : ]
        
            dictionary.updateValue(complaindate as AnyObject, forKey: kComplaintsDetaileComplaindateKey)
        
            dictionary.updateValue(replydate as AnyObject, forKey: kComplaintsDetaileReplydateKey)
        
            dictionary.updateValue(complainsource as AnyObject, forKey: kComplaintsDetaileComplainsourceKey)
        
            dictionary.updateValue(reply as AnyObject, forKey: kComplaintsDetaileReplyKey)
        
            dictionary.updateValue(detailid as AnyObject, forKey: kComplaintsDetaileDetailidKey)
        
            dictionary.updateValue(dealerid as AnyObject, forKey: kComplaintsDetaileDealeridKey)
        
            dictionary.updateValue(appraiserid as AnyObject, forKey: kComplaintsDetaileAppraiseridKey)
        
            dictionary.updateValue(detail.dictionaryRepresentation() as AnyObject, forKey: kComplaintsDetaileDetailKey)
        
            dictionary.updateValue(picurl as AnyObject, forKey: kComplaintsDetailePicurlKey)
        
            dictionary.updateValue(complainid as AnyObject, forKey: kComplaintsDetaileComplainidKey)
        
            dictionary.updateValue(complainTypeId as AnyObject, forKey: kComplaintsDetaileComplainTypeIdKey)
        
            dictionary.updateValue(dealer as AnyObject, forKey: kComplaintsDetaileDealerKey)
        
            dictionary.updateValue(osOrderComplainType.dictionaryRepresentation() as AnyObject, forKey: kComplaintsDetaileOsOrderComplainTypeKey)
        
            dictionary.updateValue(isdeal as AnyObject, forKey: kComplaintsDetaileIsdealKey)
        
            dictionary.updateValue(complaincommnet as AnyObject, forKey: kComplaintsDetaileComplaincommnetKey)
        
        
        return dictionary
    }
    
    
}
